package com.pay.web.cust;

import com.pay.model.TbCustInfo;
import com.pay.service.CustService;
import com.pay.web.proxy.ServletProxy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.annotation.Resource;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by Administrator on 2017-7-4.
 */
@WebServlet("/cust")
@Component
public class CustShowServlet extends HttpServlet {
    private static final Logger logger = LoggerFactory.getLogger(CustShowServlet.class);
    @Resource
    private CustService custService;

//    public void setCustService(CustService custService) {
//        this.custService = custService;
//    }

    @Override
    public void init() throws ServletException {
        //logger.debug("=========init()===========");
        //custService = new CustService();
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        logger.debug("==========come on baby !!===============");
        List<TbCustInfo> custList = custService.findList();
        req.setAttribute("custList",custList);
        req.getRequestDispatcher("/WEB-INF/view/cust/cust_show.jsp").forward(req,resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
//        logger.debug("========init(config)========");
//        ServletContext servletContext = config.getServletContext();
//        WebApplicationContext webApplicationContext = WebApplicationContextUtils
//                .getWebApplicationContext(servletContext);
//        AutowireCapableBeanFactory autowireCapableBeanFactory = webApplicationContext
//                .getAutowireCapableBeanFactory();
//        autowireCapableBeanFactory.configureBean(this, "custService");
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.service(req, resp);
    }
}
